using System;
using System.Collections.Generic;
using System.Text;
using LiveStock.dataAccess;
using LiveStock.Recommendation;

namespace LiveStock.Recommendation
{
    static class EvaluationRating
    {
        public static int GetRating(int userID, string newsDocument, DateTime newsDocumentDate)
        {
            Keywords.KeywordsDataTable keywordsTable = KeywordsData.KeywordsGetAll(userID);
            int weightTotal = 0;
            int recommendation = 0;
            WordCounter wc = new WordCounter(newsDocument);
            foreach (Keywords.KeywordsRow row in keywordsTable)
            {
                weightTotal += wc.GetCount(row.KeyWord) * row.Weight;
            }

            int dateMultiplier;
            int daysOldDays = Weights.WeightSelectByUserIDWeightName(userID, "DaysOldDays");
            //if the document is less than the allowed number of days old.
            if (newsDocumentDate.AddDays(Convert.ToDouble(daysOldDays)) >= DateTime.Now)
            {
                dateMultiplier = Weights.WeightSelectByUserIDWeightName(userID, "DaysOldMultiplier");
            }
            //otherwise set mult. to 1
            else
            {
                dateMultiplier = 1;
            }
            recommendation = weightTotal * dateMultiplier;
            return recommendation;
        }
    }
}
